<?php
/* ******************************
 *	Request aJax actions
 * ******************************
*/

include('../../includes/classes/core.php');
$action = $_REQUEST['act'];
$error	= '';
$data	= '';

switch ($action) {
 	case 'get_list' :
		$count 		= $_REQUEST['count'];
		$hidden 	= $_REQUEST['hidden'];
		$user		= $_SESSION['USERID'];


		mysql_query("SET @i = 0;");
	$rResult = mysql_query("SELECT	`task`.id,
                    				`task_type`.`name`,
                    				`template`.`name`,				
                    				IF(`task`.mom_1 = 1, 'კი', (IF(`task`.mom_1 = 2,'არა','')) ),
                    				`task`.mom_2,
                    				`task`.mom_3,
                    				IF(`task`.mom_4 = 1, 'კი', (IF(`task`.mom_4 = 2,'არა','')) ),
                    				IF(`task`.gad_1 = 1, 'კი', (IF(`task`.gad_1 = 2,'არა','')) ),
                    				IF(`task`.gad_2 = 1, 'კი', (IF(`task`.gad_2 = 2,'არა','')) ),
									IF(`task`.gad_3 = 1, 'კი', (IF(`task`.gad_3 = 2,'არა','')) ),
                    				IF(`task`.gad_4 = 1, 'კი', (IF(`task`.gad_4 = 2,'არა','')) ),
                    				`task`.sag_1,
                    				`task`.sag_2,
                    				`task`.sag_3,
                    				if(ISNULL(task.incomming_call_id), task.`date`, incomming_call.`date`) AS datee
                            FROM 	`task`
                            LEFT JOIN 	incomming_call ON task.incomming_call_id=incomming_call.id
                            left JOIN 	persons AS `user1`			ON task.responsible_user_id=user1.id
                            JOIN 		users AS `user2`			ON task.user_id=user2.id
                            JOIN 		persons AS `person2`		ON user2.person_id=person2.id
                            JOIN 		template ON task.template_id=template.id
                            JOIN 		task_type ON task.task_type_id=task_type.id
                            WHERE 		task.actived=1 and task.task_type_id= 1 AND task.`status`=3
									
	  			");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
    default:
       $error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);


/* ******************************
 *	Request Functions
 * ******************************
 */